<template>
  <div>
    <a-form-item>
      <a-button @click="onExport" class="btn">导出</a-button>
    </a-form-item>
    <a-form-item>
      <a-upload
        class="upload-demo"
        action=""
        accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
        :before-remove="beforeRemove"
        :http-request="uploadFile"
        multiple
        :limit="1"
        :on-exceed="handleExceed"
        :file-list="fileList"
      >
        <a-button class="btn">导入</a-button>
        <!-- <div slot="tip" class="a-upload__tip">只能上传Excel文件</div> -->
      </a-upload>
    </a-form-item>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fileList: [],
      UploadSuccess: false,
      handleExceed(files, fileList) {
        this.$message.warning(
          `当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
        )
      },
    }
  },
  methods: {
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    async DietUp_load(form) {
      const res = await Diet_Up_load(form)
      if (res.result == 0) {
        this.UploadSuccess = true
        this.$message({
          type: 'success',
          message: '上传成功!',
        })
      } else {
        this.UploadSuccess = false
        this.fileList = []
        this.$message({
          type: 'warning',
          message: '请重新导入!',
        })
      }
    },
    uploadFile(item) {
      var form = new FormData()
      form.append('file', item.file)
      this.DietUp_load(form) //导入//form接口
    },
    onExport() {
      //导出按钮
      this.pageIndex = 1
      this.get_Wxexport()
    },

    get_Wxexport() {
        let resdata=[]
        const blob = new Blob([resdata], {
        type: 'application/vnd.ms-excel',
        })
        let link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.setAttribute('download', "2020-01-01"+ '报修和维修记录.xlsx')
        link.click()
        link = null
        this.$message.success('报修和维修记录 导出成功')
        
    },
  },
}
</script>

<style>
</style>